package cn.gwm.flink.streaming.function.map;

import cn.gwm.flink.streaming.beans.trip.*;
import cn.gwm.flink.streaming.client.RedisClient;
import cn.gwm.flink.streaming.config.ChargeConfigEnum;
import cn.gwm.flink.streaming.config.TripConfigEnum;
import cn.gwm.flink.streaming.dwm.charge.util.SupplyUtil;
import cn.gwm.utils.ConfigLoader;
import cn.gwm.utils.KafkaUtils;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import org.apache.flink.api.common.functions.RichMapFunction;
import org.apache.flink.api.common.state.ValueState;
import org.apache.flink.api.common.state.ValueStateDescriptor;
import org.apache.flink.configuration.Configuration;
import redis.clients.jedis.JedisCluster;

import java.math.BigDecimal;
import java.sql.Connection;
import java.util.*;

public class TripMapFunction extends RichMapFunction<CarTrip, List<CarTripOutput>> {
    //FIXME 基础性配置
    /**
     * ready灯状态
     * 记录：判断行程关键指标
     */
    private static final int READY_LED_STATUS = 1;

    private static final double INVALID_PARAMETER = -999999;


    public TripMapFunction() {
        super();
    }

    /**
     * 行程日期
     * 记录：出现当日首条行程数据
     * 清除：出现与第二日首条行程数据、且不在总行程中
     */
    private transient ValueState<Date> tripDateValueState;

    /**
     * 行程编号数据
     * 记录：当日首次总行程开始 1
     * 记录：当日每次进入总行程+1
     * 清除：当日行程结束
     */
    private transient ValueState<Integer> totalCarTripNoValueState;

    /**
     * 总行程状态
     * 记录：ready灯不间断亮起60S
     * 清除：ready灯不间断熄灭900S
     */
    private transient ValueState<Boolean> totalTripTopicValueState;


    /**
     * 小行程主题状态
     * 记录：ready灯不间断亮起60S
     * 清除：ready灯不间断熄灭60S
     */
    private transient ValueState<Boolean> partTripTopicValueState;

    /**
     * 行程间歇主题状态
     * 记录：处于小行程主题中，ready灯亮起&&速度<2
     * 清除：处于小行程主题中，ready灯亮起&&速度>=2
     */
    private transient ValueState<Boolean> pauseTripTopicValueState;
    /**
     * 总行程速度状态
     * 记录：速度不间断大于等于2时间60S
     * 清除：速度不间断小于等于2时间60S
     */
    private transient ValueState<Boolean> totalTripSpeedTopicValueState;


    /**
     * 小行程速度主题状态
     * 记录：速度不间断大于等于2时间60S
     * 清除：速度不间断小于等于2时间60S
     */
    private transient ValueState<Boolean> partTripSpeedTopicValueState;
    /**
     * 总行程输出数据
     * 记录：总行程开始——ready灯持续亮起60S
     * 更新：行程开始时间——速度>=2的第一条
     * 更新：行程结束时间——速度>=2的最后一条
     * 清除：总行程结束——ready灯持续熄灭900S
     */
    private transient ValueState<CarTripOutput> totalCarTripOutputValueState;
    /**
     * 小行程输出数据
     * 记录：小行程开始——ready灯持续亮起60S
     * 更新：行程开始时间——速度>=2的第一条
     * 更新：行程结束时间——速度>=2的最后一条
     * 清除：小行程结束——ready灯持续熄灭60S
     */
    private transient ValueState<CarTripOutput> partCarTripOutputValueState;

    //FIXME 首次ready等亮起
    /**
     * 进入行程稳态
     * 记录：ready灯首次亮起
     * 清除：ready灯首次熄灭
     */
    private transient ValueState<Boolean> readyStatusValueState;
    /**
     * 进入行程稳态时间
     * 记录：ready灯首次亮起的时间
     * 清除：ready灯首次熄灭
     */
    private transient ValueState<DateTime> readyStartTimeValueState;
    /**
     * 记录：第一条Ready灯亮起的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripStartWithReadyValueState;

    //FIXME 速度大于等于2
    /**
     * 进入速度稳态
     * 记录：速度首次大于等于2
     * 清除：速度首次小于2稳态
     */
    private transient ValueState<Boolean> speedStartStatusValueState;
    /**
     * 进入速度稳态时间
     * 记录：速度首次大于等于2的时间
     * 清除：速度首次小于2稳态
     */
    private transient ValueState<DateTime> speedStartTimeValueState;
    /**
     * 记录：第一条满足速度稳态的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripStartWithSpeedValueState;

    //FIXME 速度小于2
    /**
     * 进入退出速度稳态
     * 记录：速度最后一次大于2
     * 清除：速度首次大于2稳态
     */
    private transient ValueState<Boolean> speedEndStatusValueState;
    /**
     * 进入速度稳态时间
     * 记录：度最后一次大于2的时间
     * 清除：速度首次大于2稳态
     */
    private transient ValueState<DateTime> speedEndTimeValueState;
    /**
     * 记录：最后一条速度大于2的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripEndWithSpeedValueState;
    /**
     * 记录：最后一条速度大于2的行程数据并且ready灯亮起
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripEndReadyWithSpeedValueState;

    //FIXME 最后一次ready灯亮起
    /**
     * 退出行程稳态
     * 记录：ready灯首次熄灭
     * 清除：ready灯首次亮起
     */
    private transient ValueState<Boolean> quitReadyStatusValueState;
    /**
     * 退出行程稳态
     * 记录：ready灯首次熄灭时间
     * 清除：ready灯首次亮起
     */
    private transient ValueState<DateTime> quitReadyStartTimeValueState;
    /**
     * 记录：最后一条Ready灯亮起的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripStartWithQuitReadyValueState;
    /**
     * 记录：上条一条Ready灯亮起的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripUpStartWithQuitReadyValueState;

    //FIXME 其他
    /**
     * 记录：最后一条Ready灯亮起的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTriptotalStartWithQuitReadyValueState;

    /**
     * 记录：最后一条Ready灯亮起的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripEndWithReadyValueState;

    /**
     * 记录：小行程中，第一条速度>=2的行程数据
     * 清除：完成当前间歇行程时
     */
    private transient ValueState<CarTrip> carTripSpeedFirstZeroValueState;
    /**
     * 记录：小行程中，最后一条速度>=2的行程数据
     * 清除：完成当前间歇行程时
     */
    private transient ValueState<CarTrip> carTripSpeedLastZeroValueState;
    /**
     * 退出行程稳态
     * 记录：ready灯首次熄灭时间
     * 清除：ready灯首次亮起
     */
    private transient ValueState<DateTime> carTripStartWithQuitReadyTimeValueState;
    /**
     * 退出行程稳态
     * 记录：ready灯首次熄灭时间
     * 清除：ready灯首次亮起
     */
    private transient ValueState<DateTime> carTriptotalStartWithQuitReadyTimeValueState;
    /**
     * 退出行程稳态
     * 记录：ready灯首次熄灭时间
     * 清除：ready灯首次亮起
     */
    private transient ValueState<CarTrip> carTripStartWithQuitReadySeconedValueState;
    /**
     * 记录：最后一条速度大于2的行程数据
     * 清除：完成当前小行程时
     */
    private transient ValueState<CarTrip> carTripEndWithSpeedSeconedValueState;
    /**
     * 大行程行驶时间
     * 记录：大行程开始
     * 清除：大行程结束
     */
    private transient ValueState<Long> totalTripDurationTimeValueState;
    /**
     * 小行程行驶时间
     * 记录：大行程开始
     * 清除：大行程结束
     */
    private transient ValueState<Long> partTripDurationTimeValueState;
    /**
     * 行程公里数
     * 记录：每条合法的数据
     * 清除：每条更新
     */
    private transient ValueState<Double> ipVehTotDistanceValueState;
    /**
     * 上条数据时间戳
     * 记录：每条数据更新
     * 清除：每条更新
     */
    private transient ValueState<Long> tripItemTimeValueState;
    /**
     * adCode
     * 记录：每次大行程结束
     * 清除：无
     */
    private transient ValueState<String> endAdCodeValueState;
    /**
     * 最新GPS数据
     * 记录：最新数据
     * 清除：无
     */
    private transient ValueState<CarTrip> endTripGpsValueState;
    /**
     * tripGlag
     * 记录：行程完整性校验
     * 清除：无
     */
    private transient ValueState<String> tripGlagValueState;
    /**
     * 稳态
     * 记录：全局配置参数可修改
     * 清除：无
     */
    //private static final int SteadyStateDuration = Integer.valueOf(ChargeConfigEnum.DATAPERSISTENCE.getValue());
    private static final int SteadyStateDuration = 30;
    /**
     * 行程中断
     * 记录：全局配置参数可修改
     * 清除：无
     */
    //private static final int TripTimeoutDuration = Integer.valueOf(TripConfigEnum.INTERRUPT.getValue())*60;
    private static final int TripTimeoutDuration = 600;
    /**
     * 行程最低速度
     * 记录：全局配置参数可修改
     * 清除：无
     */
    private static final int CurrentVelocityThreshold = Integer.valueOf(ConfigLoader.get("CURRENT.VELOCITY.THRESHOLD"));
    //private static final int CurrentVelocityThreshold = 2;
    /**
     * 行程间隔
     * 记录：全局配置参数可修改
     * 清除：无
     */
    private static final int TripPauseDuration = Integer.valueOf(ConfigLoader.get("TRIP.PAUSE.DURATION"));
    //private static final int TripPauseDuration = 120;
    int i = 1;

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);
        //FIXME 基础性配置
        ValueStateDescriptor<Date> tripDateValueStateDescriptor = new ValueStateDescriptor<>("tripDateValueStateDescriptor", Date.class);
        tripDateValueState = getRuntimeContext().getState(tripDateValueStateDescriptor);

        ValueStateDescriptor<Integer> totalCarTripNoValueStateDescriptor = new ValueStateDescriptor<>("totalCarTripNoValueStateDescriptor", Integer.class);
        totalCarTripNoValueState = getRuntimeContext().getState(totalCarTripNoValueStateDescriptor);

        ValueStateDescriptor<Boolean> totalTripTopicValueStateDescriptor = new ValueStateDescriptor<>("totalTripTopicValueStateDescriptor", Boolean.class);
        totalTripTopicValueState = getRuntimeContext().getState(totalTripTopicValueStateDescriptor);

        ValueStateDescriptor<Boolean> partTripTopicValueStateDescriptor = new ValueStateDescriptor<>("partTripTopicValueStateDescriptor", Boolean.class);
        partTripTopicValueState = getRuntimeContext().getState(partTripTopicValueStateDescriptor);

        ValueStateDescriptor<Boolean> pauseTripTopicValueStateDescriptor = new ValueStateDescriptor<>("pauseTripTopicValueStateDescriptor", Boolean.class);
        pauseTripTopicValueState = getRuntimeContext().getState(pauseTripTopicValueStateDescriptor);

        ValueStateDescriptor<Boolean> totalTripSpeedTopicValueStateDescriptor = new ValueStateDescriptor<>("totalTripSpeedTopicValueStateDescriptor", Boolean.class);
        totalTripSpeedTopicValueState = getRuntimeContext().getState(totalTripSpeedTopicValueStateDescriptor);

        ValueStateDescriptor<Boolean> partTripSpeedTopicValueStateDescriptor = new ValueStateDescriptor<>("partTripSpeedTopicValueStateDescriptor", Boolean.class);
        partTripSpeedTopicValueState = getRuntimeContext().getState(partTripSpeedTopicValueStateDescriptor);

        ValueStateDescriptor<CarTripOutput> totalCarTripOutputValueStateDescriptor = new ValueStateDescriptor<>("totalCarTripOutputValueStateDescriptor", CarTripOutput.class);
        totalCarTripOutputValueState = getRuntimeContext().getState(totalCarTripOutputValueStateDescriptor);

        ValueStateDescriptor<CarTripOutput> partCarTripOutputValueStateDescriptor = new ValueStateDescriptor<>("partCarTripOutputValueStateDescriptor", CarTripOutput.class);
        partCarTripOutputValueState = getRuntimeContext().getState(partCarTripOutputValueStateDescriptor);

        //FIXME 首次ready等亮起
        ValueStateDescriptor<Boolean> readyStatusValueStateDescriptor = new ValueStateDescriptor<>("readyStatusValueStateDescriptor", Boolean.class);
        readyStatusValueState = getRuntimeContext().getState(readyStatusValueStateDescriptor);

        ValueStateDescriptor<DateTime> readyStartTimeValueStateDescriptor = new ValueStateDescriptor<>("readyStartTimeValueStateDescriptor", DateTime.class);
        readyStartTimeValueState = getRuntimeContext().getState(readyStartTimeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripStartWithReadyValueStateDescriptor = new ValueStateDescriptor<>("carTripStartWithReadyValueStateDescriptor", CarTrip.class);
        carTripStartWithReadyValueState = getRuntimeContext().getState(carTripStartWithReadyValueStateDescriptor);

        //FIXME 首次速度大于等于2
        ValueStateDescriptor<Boolean> speedStartStatusValueStateDescriptor = new ValueStateDescriptor<>("speedStartStatusValueStateDescriptor", Boolean.class);
        speedStartStatusValueState = getRuntimeContext().getState(speedStartStatusValueStateDescriptor);

        ValueStateDescriptor<DateTime> speedStartTimeValueStateDescriptor = new ValueStateDescriptor<>("speedStartTimeValueStateDescriptor", DateTime.class);
        speedStartTimeValueState = getRuntimeContext().getState(speedStartTimeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripStartWithSpeedValueStateDescriptor = new ValueStateDescriptor<>("carTripStartWithSpeedValueStateDescriptor", CarTrip.class);
        carTripStartWithSpeedValueState = getRuntimeContext().getState(carTripStartWithSpeedValueStateDescriptor);
        //FIXME 最后一次速度大于2

        ValueStateDescriptor<Boolean> speedEndStatusValueStateDescriptor = new ValueStateDescriptor<>("speedEndStatusValueStateDescriptor", Boolean.class);
        speedEndStatusValueState = getRuntimeContext().getState(speedEndStatusValueStateDescriptor);

        ValueStateDescriptor<DateTime> speedEndTimeValueStateDescriptor = new ValueStateDescriptor<>("speedEndTimeValueStateDescriptor", DateTime.class);
        speedEndTimeValueState = getRuntimeContext().getState(speedEndTimeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripEndWithSpeedValueStateDescriptor = new ValueStateDescriptor<>("carTripEndWithSpeedValueStateDescriptor", CarTrip.class);
        carTripEndWithSpeedValueState = getRuntimeContext().getState(carTripEndWithSpeedValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripEndReadyWithSpeedValueStateDescriptor = new ValueStateDescriptor<>("carTripEndReadyWithSpeedValueStateDescriptor", CarTrip.class);
        carTripEndReadyWithSpeedValueState = getRuntimeContext().getState(carTripEndReadyWithSpeedValueStateDescriptor);

        //FIXME 最后一次ready等亮起
        ValueStateDescriptor<Boolean> quitReadyStatusValueStateDescriptor = new ValueStateDescriptor<>("quitReadyStatusValueStateDescriptor", Boolean.class);
        quitReadyStatusValueState = getRuntimeContext().getState(quitReadyStatusValueStateDescriptor);


        ValueStateDescriptor<DateTime> quitReadyStartTimeValueStateDescriptor = new ValueStateDescriptor<>("quitReadyStartTimeValueStateDescriptor", DateTime.class);
        quitReadyStartTimeValueState = getRuntimeContext().getState(quitReadyStartTimeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripStartWithQuitReadyValueStateDescriptor = new ValueStateDescriptor<>("carTripStartWithQuitReadyValueStateDescriptor", CarTrip.class);
        carTripStartWithQuitReadyValueState = getRuntimeContext().getState(carTripStartWithQuitReadyValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripUpStartWithQuitReadyValueStateDescriptor = new ValueStateDescriptor<>("carTripUpStartWithQuitReadyValueStateDescriptor", CarTrip.class);
        carTripUpStartWithQuitReadyValueState = getRuntimeContext().getState(carTripUpStartWithQuitReadyValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTriptotalStartWithQuitReadyValueStateDescriptor = new ValueStateDescriptor<>("carTriptotalStartWithQuitReadyValueStateDescriptor", CarTrip.class);
        carTriptotalStartWithQuitReadyValueState = getRuntimeContext().getState(carTriptotalStartWithQuitReadyValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripEndWithReadyValueStateDescriptor = new ValueStateDescriptor<>("carTripEndWithReadyValueStateDescriptor", CarTrip.class);
        carTripEndWithReadyValueState = getRuntimeContext().getState(carTripEndWithReadyValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripSpeedFirstZeroValueStateDescriptor = new ValueStateDescriptor<>("carTripSpeedFirstZeroValueStateDescriptor", CarTrip.class);
        carTripSpeedFirstZeroValueState = getRuntimeContext().getState(carTripSpeedFirstZeroValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripSpeedLastZeroValueStateDescriptor = new ValueStateDescriptor<>("carTripSpeedLastZeroValueStateDescriptor", CarTrip.class);
        carTripSpeedLastZeroValueState = getRuntimeContext().getState(carTripSpeedLastZeroValueStateDescriptor);

        ValueStateDescriptor<DateTime> carTripStartWithQuitReadyTimeValueStateDescriptor = new ValueStateDescriptor<>("carTripStartWithQuitReadyTimeValueStateDescriptor", DateTime.class);
        carTripStartWithQuitReadyTimeValueState = getRuntimeContext().getState(carTripStartWithQuitReadyTimeValueStateDescriptor);

        ValueStateDescriptor<DateTime> carTriptotalStartWithQuitReadyTimeValueStateDescriptor = new ValueStateDescriptor<>("carTriptotalStartWithQuitReadyTimeValueStateDescriptor", DateTime.class);
        carTriptotalStartWithQuitReadyTimeValueState = getRuntimeContext().getState(carTriptotalStartWithQuitReadyTimeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripStartWithQuitReadySeconedValueStateDescriptor = new ValueStateDescriptor<>("carTripStartWithQuitReadySeconedValueStateDescriptor", CarTrip.class);
        carTripStartWithQuitReadySeconedValueState = getRuntimeContext().getState(carTripStartWithQuitReadySeconedValueStateDescriptor);

        ValueStateDescriptor<CarTrip> carTripEndWithSpeedSeconedValueStateDescriptor = new ValueStateDescriptor<>("carTripEndWithSpeedSeconedValueStateDescriptor", CarTrip.class);
        carTripEndWithSpeedSeconedValueState = getRuntimeContext().getState(carTripEndWithSpeedSeconedValueStateDescriptor);

        ValueStateDescriptor<Long> totalTripDurationTimeValueStateDescriptor = new ValueStateDescriptor<>("totalTripDurationTimeValueStateDescriptor", Long.class);
        totalTripDurationTimeValueState = getRuntimeContext().getState(totalTripDurationTimeValueStateDescriptor);

        ValueStateDescriptor<Long> partTripDurationTimeValueStateDescriptor = new ValueStateDescriptor<>("partTripDurationTimeValueStateDescriptor", Long.class);
        partTripDurationTimeValueState = getRuntimeContext().getState(partTripDurationTimeValueStateDescriptor);

        ValueStateDescriptor<Double> ipVehTotDistanceValueStateDescriptor = new ValueStateDescriptor<>("ipVehTotDistanceValueStateDescriptor", Double.class);
        ipVehTotDistanceValueState = getRuntimeContext().getState(ipVehTotDistanceValueStateDescriptor);

        ValueStateDescriptor<Long> tripItemTimeValueStateDescriptor = new ValueStateDescriptor<>("tripItemTimeValueStateDescriptor", Long.class);
        tripItemTimeValueState = getRuntimeContext().getState(tripItemTimeValueStateDescriptor);

        ValueStateDescriptor<String> endAdCodeValueStateDescriptor = new ValueStateDescriptor<>("endAdCodeValueStateDescriptor", String.class);
        endAdCodeValueState = getRuntimeContext().getState(endAdCodeValueStateDescriptor);

        ValueStateDescriptor<CarTrip> endTripGpsValueStateDescriptor = new ValueStateDescriptor<>("endTripGpsValueStateDescriptor", CarTrip.class);
        endTripGpsValueState = getRuntimeContext().getState(endTripGpsValueStateDescriptor);

        ValueStateDescriptor<String> tripGlagValueStateDescriptor = new ValueStateDescriptor<>("tripGlagValueStateDescriptor", String.class);
        tripGlagValueState = getRuntimeContext().getState(tripGlagValueStateDescriptor);
    }

    @Override
    public List<CarTripOutput> map(CarTrip carTrip) throws Exception {
        List<CarTripOutput> carTripOutputList=new ArrayList<>();
        //临时添加过滤时间
        if(ObjectUtil.isEmpty(tripItemTimeValueState.value())) {
            tripItemTimeValueState.update(carTrip.getItem_time());
        }
        //if (carTrip.getDeviceId().equals("TLGWEE23060215482")) {
        if (carTrip.getItem_time() >= tripItemTimeValueState.value()||ObjectUtil.isEmpty(tripItemTimeValueState.value())) {
             //System.out.println(StrUtil.format("VIN:{}————TIME:{}————ready灯:{}————速度:{}————IP_VehTotDistance:{}————I为:{}", carTrip.getDeviceId(), DateUtil.date(carTrip.getItem_time()), carTrip.getVCU_RdyLEDSts_RM(), carTrip.getVehSpd(),carTrip.getIP_VehTotDistance(), i));
             //i++;
            //临时添加更新每条数据时间戳
            if(ObjectUtil.isNotEmpty(carTrip.getItem_time())) {
                tripItemTimeValueState.update(carTrip.getItem_time());
            }
/*        if(carTrip.getItem_time()>=1668430600000L){
            System.err.println(StrUtil.format("carTrip.getItem_time():{}",  DateUtil.date(carTrip.getItem_time())));
        }*/
            //初始化ValueState
            if (ObjectUtil.isEmpty(carTrip.getDeviceId()) || ObjectUtil.isEmpty(carTrip.getItem_time())) {
                return null;
            }

            if (ObjectUtil.isEmpty(carTrip.getVCU_RdyLEDSts_RM())) {
                carTrip.setVCU_RdyLEDSts_RM(0);
            }

            if (ObjectUtil.isEmpty(carTrip.getVehSpd())) {
                carTrip.setVehSpd(Convert.toBigDecimal(0));
            }

            //FIXME 更新最新一条表显里程的数据
            if (carTrip.getIP_VehTotDistance() != INVALID_PARAMETER) {
                if(ObjectUtil.isNotEmpty(ipVehTotDistanceValueState.value())){
                    if(ObjectUtil.isEmpty(tripGlagValueState.value())){
                        tripGlagValueState.update("0");
                    }
                    //&& ObjectUtil.isNotEmpty(partTripTopicValueState.value())
                    //if(countDuration(Convert.toLong(ipVehTotDistanceValueState.value()),Convert.toLong(carTrip.getIP_VehTotDistance())) >= 2L )
                    if(Math.abs(carTrip.getIP_VehTotDistance() - ipVehTotDistanceValueState.value()) >=2D)
                    {
                        tripGlagValueState.update("1");
                        System.out.println(StrUtil.format("tripGlagValueState[2]:{}", tripGlagValueState.value()));
                    }
                }
                ipVehTotDistanceValueState.update(carTrip.getIP_VehTotDistance());
            }

            //FIXME 行程主题日期判断
            if (ObjectUtil.isEmpty(tripDateValueState.value())) {
                tripDateValueState.update(DateUtil.date(carTrip.getItem_time()));
            } else {
                long duration = DateUtil.between(DateUtil.beginOfDay(tripDateValueState.value()), DateUtil.beginOfDay(DateUtil.date(carTrip.getItem_time())), DateUnit.DAY);
                //FIXME 行程时间逾日 则清理行程数据
                if (duration >= 1 && ObjectUtil.isEmpty(totalTripTopicValueState.value()) && ObjectUtil.isEmpty(partTripTopicValueState.value())&&ObjectUtil.isEmpty(carTripStartWithReadyValueState.value())) {
                    //FIXME 基础性配置
                    //tripDateValueState.clear();
                    totalCarTripNoValueState.clear();
                    totalTripTopicValueState.clear();
                    partTripTopicValueState.clear();
                    pauseTripTopicValueState.clear();
                    totalTripSpeedTopicValueState.clear();
                    partTripSpeedTopicValueState.clear();
                    totalCarTripOutputValueState.clear();
                    partCarTripOutputValueState.clear();
                    //FIXME 首次ready等亮起
                    readyStatusValueState.clear();
                    readyStartTimeValueState.clear();
                    carTripStartWithReadyValueState.clear();
                    //FIXME 速度大于等于2
                    speedStartStatusValueState.clear();
                    speedStartTimeValueState.clear();
                    carTripStartWithSpeedValueState.clear();
                    //FIXME 速度小于2
                    speedEndStatusValueState.clear();
                    speedEndTimeValueState.clear();
                    carTripEndWithSpeedValueState.clear();
                    carTripEndReadyWithSpeedValueState.clear();
                    //FIXME 最后一次ready等亮起
                    quitReadyStatusValueState.clear();
                    quitReadyStartTimeValueState.clear();
                    carTripStartWithQuitReadyValueState.clear();
                    //FIXME 其他
                    carTriptotalStartWithQuitReadyValueState.clear();
                    carTripEndWithReadyValueState.clear();
                    carTripSpeedFirstZeroValueState.clear();
                    carTripSpeedLastZeroValueState.clear();
                    carTripStartWithQuitReadyTimeValueState.clear();
                    carTriptotalStartWithQuitReadyTimeValueState.clear();
                    carTripStartWithQuitReadySeconedValueState.clear();
                    carTripEndWithSpeedSeconedValueState.clear();
                    tripDateValueState.update(DateUtil.date(carTrip.getItem_time()));
                    totalTripDurationTimeValueState.clear();
                    partTripDurationTimeValueState.clear();
                    carTripUpStartWithQuitReadyValueState.clear();
                    tripGlagValueState.clear();
                    //IP_VehTotDistanceValueState.clear();
                }
            }
            //FIXME 更新最新一条ready灯亮起的数据
            if (carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS) {
                //完整性验证行程过程中数据中断一分钟
                if(ObjectUtil.isNotEmpty(partTripTopicValueState.value())&&ObjectUtil.isNotEmpty(carTripStartWithQuitReadyValueState.value())){
                    if(countDuration(DateUtil.date(carTripStartWithQuitReadyValueState.value().getItem_time()), DateUtil.date(carTrip.getItem_time()))>=SteadyStateDuration){
                        tripGlagValueState.update("1");
                        System.out.println(StrUtil.format("tripGlagValueState[1]:{}", tripGlagValueState.value()));
                    }
                }
                carTripUpStartWithQuitReadyValueState.update(carTripStartWithQuitReadyValueState.value());
                carTripStartWithQuitReadyValueState.update(carTrip);
                if (ObjectUtil.isEmpty(totalTripTopicValueState.value()) || ObjectUtil.isEmpty(partTripTopicValueState.value())) {
                    if(ObjectUtil.isNotEmpty(carTripUpStartWithQuitReadyValueState.value())) {
                        long duration6=countDuration(DateUtil.date(carTripUpStartWithQuitReadyValueState.value().getItem_time()), DateUtil.date(carTripStartWithQuitReadyValueState.value().getItem_time()));
                        if(duration6 > TripTimeoutDuration) {
                            readyStatusValueState.clear();
                            readyStartTimeValueState.clear();
                            carTripStartWithReadyValueState.clear();
                            speedStartStatusValueState.clear();
                            speedStartTimeValueState.clear();
                            carTripStartWithSpeedValueState.clear();
                            carTripSpeedFirstZeroValueState.clear();
                        }
                    }
                }
            }
            //FIXME 速度大于等于2
            if (Convert.toInt(carTrip.getVehSpd()) >= CurrentVelocityThreshold) {
                if (ObjectUtil.isEmpty(carTripStartWithSpeedValueState.value())) {
                    carTripStartWithSpeedValueState.update(carTrip);
                }
            }

            //FIXME 速度<2时，记录数据供后续调用  carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS&&
            if (Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold) {
                //存在最新一条速度<2的行程数据
                if (ObjectUtil.isEmpty(carTripSpeedFirstZeroValueState.value())) {
                    carTripSpeedFirstZeroValueState.update(carTrip);
                }
                carTripSpeedLastZeroValueState.update(carTrip);
            }
             //FIXME 更新最新GPS信号
            if(carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS && ObjectUtil.isNotEmpty(carTrip.getItem_time()) && carTrip.getItem_time()!=INVALID_PARAMETER && ObjectUtil.isNotEmpty(carTrip.getLatitude()) && carTrip.getLatitude().compareTo(Convert.toBigDecimal(INVALID_PARAMETER)) != 0 && ObjectUtil.isNotEmpty(carTrip.getLongitude()) && carTrip.getLongitude().compareTo(Convert.toBigDecimal(INVALID_PARAMETER)) !=0  ){
                endTripGpsValueState.update(carTrip);
            }

            //FIXME 当前数据Ready灯亮 速度>=2进入稳态carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS &&
            if (Convert.toInt(carTrip.getVehSpd()) >= CurrentVelocityThreshold) {
                //首次进入速度稳态
                if(ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value())||ObjectUtil.isNotEmpty(partTripSpeedTopicValueState.value())) {
                    speedEndStatusValueState.clear();
                    speedEndTimeValueState.clear();
                    carTripSpeedFirstZeroValueState.clear();
                }
                if (ObjectUtil.isEmpty(speedStartStatusValueState.value()) || !speedStartStatusValueState.value()) {
                    speedStartStatusValueState.update(true);
                    speedStartTimeValueState.update(DateUtil.date(carTripStartWithSpeedValueState.value().getItem_time()));
                }
                //FIXME 持续速度大于2判断
                if (ObjectUtil.isNotEmpty(speedStartStatusValueState.value()) || speedStartStatusValueState.value()) {
                    long duration = countDuration(DateUtil.date(speedStartTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));
                    if (duration >= SteadyStateDuration) {
                        if (ObjectUtil.isEmpty(totalTripSpeedTopicValueState.value())) {
                            totalTripSpeedTopicValueState.update(true);
                        }
                        if (ObjectUtil.isEmpty(partTripSpeedTopicValueState.value())) {
                            partTripSpeedTopicValueState.update(true);
                        }
                        if(ObjectUtil.isNotEmpty(partTripSpeedTopicValueState.value())){
                            if(ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())){
                                carTripEndWithSpeedSeconedValueState.update(carTripEndWithSpeedValueState.value());
                            }
                            carTripEndWithSpeedValueState.update(carTrip);
                        }
                        if(carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS && ObjectUtil.isNotEmpty(partTripSpeedTopicValueState.value())){
                            carTripEndReadyWithSpeedValueState.update(carTrip);
                        }
                        //FIXME 行程间歇

                        if (ObjectUtil.isNotEmpty(partTripTopicValueState.value())&&ObjectUtil.isNotEmpty(pauseTripTopicValueState.value())&&ObjectUtil.isNotEmpty(carTripSpeedFirstZeroValueState.value())&&ObjectUtil.isNotEmpty(carTripSpeedLastZeroValueState.value())) {
                            long duration4 = countDuration(DateUtil.date(carTripSpeedFirstZeroValueState.value().getItem_time()), DateUtil.date(carTripSpeedLastZeroValueState.value().getItem_time()));
                            if (duration4 >= TripPauseDuration) {
                                CarTripOutput pauseCarTripOutput = new CarTripOutput(CarTripOutput.PAUSE_TRIP);
                                pauseCarTripOutput = constructCarTripStartData(carTripSpeedFirstZeroValueState.value(), pauseCarTripOutput);
                                //System.out.println(StrUtil.format("carTripSpeedFirstZeroValueState.value().getItem_time():{}————--行程间歇开始时间[11111]---", DateUtil.date(Convert.toDate(carTripSpeedFirstZeroValueState.value().getItem_time()))));
                                pauseCarTripOutput.setTripstarttime(DateUtil.date(carTripSpeedFirstZeroValueState.value().getItem_time()).toString());
                                pauseCarTripOutput.setMaxduration(Convert.toStr(duration4));
                                //System.out.println(StrUtil.format("carTripSpeedLastZeroValueState.value().getItem_time():{}————--行程间歇结束时间[11111]---", DateUtil.date(Convert.toDate(carTripSpeedLastZeroValueState.value().getItem_time()))));
                                //System.out.println(StrUtil.format("pauseCarTripOutput.getMaxduration():{}————--行程间歇时间[11111]---", pauseCarTripOutput.getMaxduration()));
                                pauseCarTripOutput.setTripendtime(DateUtil.date(carTripSpeedLastZeroValueState.value().getItem_time()).toString());
                                pauseCarTripOutput = constructCarTripEndData(carTripSpeedLastZeroValueState.value(), pauseCarTripOutput);
                                pauseTripTopicValueState.clear();

                                carTripOutputList.add(pauseCarTripOutput);
                                //return CarTripOutputList;
                            }
                        }
                        speedEndStatusValueState.clear();
                        speedEndTimeValueState.clear();
                        carTripSpeedFirstZeroValueState.clear();
                    }
                }
            }
            //FIXME 当前数据Ready灯亮 速度< 2进入稳态 carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS &&
            if (ObjectUtil.isNotEmpty(partTripTopicValueState.value())&& Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold) {
                //首次进入退出速度稳态
                if (ObjectUtil.isEmpty(totalTripSpeedTopicValueState.value()) || ObjectUtil.isEmpty(partTripSpeedTopicValueState.value())||!totalTripSpeedTopicValueState.value()||!partTripSpeedTopicValueState.value()) {
                    speedStartStatusValueState.clear();
                    speedStartTimeValueState.clear();
                    carTripStartWithSpeedValueState.clear();
                }

                if (ObjectUtil.isEmpty(speedEndStatusValueState.value()) || !speedEndStatusValueState.value()) {
                    speedEndStatusValueState.update(true);
                    speedEndTimeValueState.update(DateUtil.date(carTripSpeedFirstZeroValueState.value().getItem_time()));
                }
                //FIXME 持续速度小于2判断
                if (ObjectUtil.isNotEmpty(speedEndStatusValueState.value()) || speedEndStatusValueState.value()) {
                    long duration = countDuration(DateUtil.date(speedEndTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));
                    if (duration >= SteadyStateDuration) {
                        if (ObjectUtil.isEmpty(pauseTripTopicValueState.value())) {
                            pauseTripTopicValueState.update(true);
                        }
                        //大行程累加时间
                        if(ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value()) && ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value()) && ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value().getItem_time())) {
                            if(ObjectUtil.isEmpty(totalTripDurationTimeValueState.value())){
                                totalTripDurationTimeValueState.update(0L);
                            }
                            if(ObjectUtil.isEmpty(partTripDurationTimeValueState.value())){
                                partTripDurationTimeValueState.update(0L);
                            }
                            if(carTripEndWithSpeedValueState.value().getItem_time()> carTripStartWithQuitReadyValueState.value().getItem_time() || duration >= TripTimeoutDuration){
                                if(ObjectUtil.isNotEmpty(carTripEndReadyWithSpeedValueState.value())) {
                                    carTripEndWithSpeedValueState.update(carTripEndReadyWithSpeedValueState.value());
                                    //System.out.println(StrUtil.format("carTripEndWithSpeedValueState.value().getItem_time():{}————--赋值后---", DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                }
                            }
                            if(carTripStartWithSpeedValueState.value().getItem_time() < carTripEndWithSpeedValueState.value().getItem_time()) {
                                //System.out.println(StrUtil.format("carTripStartWithSpeedValueState.value().getItem_time():{}————--行程开始时间[1]---", DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time()))));
                                //System.out.println(StrUtil.format("carTripEndWithSpeedValueState.value().getItem_time():{}————--行程结束时间[1]---", DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                //System.out.println(StrUtil.format("carTripStartWithQuitReadyValueState.value().getItem_time():{}————--下高压时间[1]---", DateUtil.date(Convert.toDate(carTripStartWithQuitReadyValueState.value().getItem_time()))));
                                totalTripDurationTimeValueState.update(totalTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time())), DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                partTripDurationTimeValueState.update(partTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time())), DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                //System.out.println(StrUtil.format("VIN:{}————--行程时间为[1]---", totalTripDurationTimeValueState.value()));
                            }
                        }
                        speedStartStatusValueState.clear();
                        speedStartTimeValueState.clear();
                        carTripStartWithSpeedValueState.clear();
                        totalTripSpeedTopicValueState.clear();
                        partTripSpeedTopicValueState.clear();
                        //System.out.println(StrUtil.format("VIN:{}————--持续速度下与2---", carTrip.getDeviceId()));
                    }
                }
            }

            //FIXME 当前数据Ready灯亮 进入稳态
            if (carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS) {
                //首次进入稳态
                if (ObjectUtil.isEmpty(readyStatusValueState.value()) || !readyStatusValueState.value()) {
                    readyStatusValueState.update(true);
                    readyStartTimeValueState.update(DateUtil.date(carTrip.getItem_time()));
                    carTripStartWithReadyValueState.update(carTrip);
                }
                if (ObjectUtil.isNotEmpty(totalTripTopicValueState.value()) || ObjectUtil.isNotEmpty(partTripTopicValueState.value())) {
                    if (totalTripTopicValueState.value() || partTripTopicValueState.value()) {
                        quitReadyStatusValueState.clear();
                        quitReadyStartTimeValueState.clear();
                    }
                }

                if(ObjectUtil.isEmpty(partTripSpeedTopicValueState.value())&&ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value())&&Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold){
                    speedStartStatusValueState.clear();
                    speedStartTimeValueState.clear();
                    carTripStartWithSpeedValueState.clear();
                }
                //状态值为1开始断点========================start
                //FIXME Ready灯熄灭后不够一分钟或者十五分钟没信号了，下次有信号直接Ready亮
                if(ObjectUtil.isNotEmpty(carTriptotalStartWithQuitReadyTimeValueState.value())){
                    long duration1 = DateUtil.between(DateUtil.beginOfDay(tripDateValueState.value()), DateUtil.beginOfDay(DateUtil.date(carTrip.getItem_time())), DateUnit.DAY);
                    if (ObjectUtil.isNotEmpty(totalTripTopicValueState.value())) {
                        if(ObjectUtil.isNotEmpty(carTripStartWithQuitReadySeconedValueState.value())) {
                            long duration2=0;
                            if(Convert.toLong(DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()))<Convert.toLong(DateUtil.date(carTriptotalStartWithQuitReadyTimeValueState.value()))) {
                                duration2 = countDuration(DateUtil.date(carTriptotalStartWithQuitReadyTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));
                            }else {
                                duration2 = countDuration(DateUtil.date(carTriptotalStartWithQuitReadyTimeValueState.value()), DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()));
                            }
                            //TODO 退出稳态持续达到900S 退出大小行程
                            if (duration2 > TripTimeoutDuration) {
                                //根据行程状态决定行程结束时间
                                if(ObjectUtil.isEmpty(totalTripSpeedTopicValueState.value())||ObjectUtil.isEmpty(partTripSpeedTopicValueState.value())||Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold){
                                    if(ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripStartWithQuitReadySeconedValueState.value())) {
                                        if (carTripEndWithSpeedValueState.value().getItem_time() > carTripStartWithQuitReadySeconedValueState.value().getItem_time()) {
                                            if (ObjectUtil.isNotEmpty(carTripEndReadyWithSpeedValueState.value())) {
                                                carTripEndWithSpeedValueState.update(carTripEndReadyWithSpeedValueState.value());
                                            }
                                        }
                                    }
                                    carTripEndWithSpeedSeconedValueState.update(carTripEndWithSpeedValueState.value());
                                }
                                if(ObjectUtil.isNotEmpty(partTripTopicValueState.value())) {
                                    //记录子行程结束
                                    CarTripOutput partCarTripOutput = partCarTripOutputValueState.value();
                                    if (ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())) {
                                        partCarTripOutput = constructCarTripEndData(carTripEndWithSpeedSeconedValueState.value(), partCarTripOutput);
                                        partCarTripOutput.setEndbmssoc(null);
                                        partCarTripOutput.setEndbmssoe(null);
                                        partCarTripOutput.setEndbmssoh(null);
                                        partCarTripOutput.setEndbmsmoduletempmax(null);
                                        partCarTripOutput.setEndbmsmoduletempmin(null);
                                        partCarTripOutput.setEndbmsmoduletempaverage(null);
                                        partCarTripOutput.setEndincartemp(null);
                                        partCarTripOutput.setIpvehtotdistance(null);
                                    }
                                    if (ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())) {
                                        Boolean timeBefore = DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).isBefore(DateUtil.date(carTripEndWithSpeedSeconedValueState.value().getItem_time()));
                                        if (timeBefore) {
                                            partCarTripOutput.setTripendtime(DateUtil.date(carTripEndWithSpeedSeconedValueState.value().getItem_time()).toString());
                                            partCarTripOutput.setEndbmssoc(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOC(), 0d));
                                            partCarTripOutput.setEndbmssoe(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOE(), 0d));
                                            partCarTripOutput.setEndbmssoh(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOH(), 0d));
                                            partCarTripOutput.setEndbmsmoduletempmax(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMax());
                                            partCarTripOutput.setEndbmsmoduletempmin(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMin());
                                            partCarTripOutput.setEndbmsmoduletempaverage(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMin());
                                            partCarTripOutput.setEndincartemp(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getInCarTemp(), 0d));
                                            if (carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance() == INVALID_PARAMETER) {
                                                partCarTripOutput.setEndipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                                            } else {
                                                partCarTripOutput.setEndipvehtotdistance(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance(), 0d));
                                            }
                                        }
                                        //大行程累加时间
                                        if(ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value().getItem_time())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value().getItem_time())&&ObjectUtil.isNotEmpty(speedStartTimeValueState.value())) {
                                            if (carTripStartWithSpeedValueState.value().getItem_time() < carTripEndWithSpeedSeconedValueState.value().getItem_time()) {
                                                if (ObjectUtil.isEmpty(totalTripDurationTimeValueState.value())) {
                                                    totalTripDurationTimeValueState.update(0L);
                                                }
                                                if (ObjectUtil.isEmpty(partTripDurationTimeValueState.value())) {
                                                    partTripDurationTimeValueState.update(0L);
                                                }
                                                if(carTripEndWithSpeedValueState.value().getItem_time()> carTripStartWithQuitReadyValueState.value().getItem_time() || duration2 >= TripTimeoutDuration){
                                                    if(ObjectUtil.isNotEmpty(carTripEndReadyWithSpeedValueState.value())) {
                                                        carTripEndWithSpeedValueState.update(carTripEndReadyWithSpeedValueState.value());
                                                        //System.out.println(StrUtil.format("carTripEndWithSpeedValueState.value().getItem_time():{}————--赋值后---", DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                                    }
                                                }
                                                //System.out.println(StrUtil.format("carTripStartWithSpeedValueState.value().getItem_time():{}————--行程开始时间[2]---", DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time()))));
                                                //System.out.println(StrUtil.format("carTripEndWithSpeedSeconedValueState.value().getItem_time():{}————--行程结束时间[2]---", DateUtil.date(Convert.toDate(carTripEndWithSpeedSeconedValueState.value().getItem_time()))));
                                                totalTripDurationTimeValueState.update(totalTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time())), DateUtil.date(Convert.toDate(carTripEndWithSpeedSeconedValueState.value().getItem_time()))));
                                                partTripDurationTimeValueState.update(partTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(carTripStartWithSpeedValueState.value().getItem_time())), DateUtil.date(Convert.toDate(carTripEndWithSpeedSeconedValueState.value().getItem_time()))));
                                                //System.out.println(StrUtil.format("VIN:{}————--行程时间为[2]---", totalTripDurationTimeValueState.value()));
                                            }
                                        }
                                    }
                                    if(ObjectUtil.isNotEmpty(partTripDurationTimeValueState.value())) {
                                        partCarTripOutput.setTripduration(partTripDurationTimeValueState.value().toString());
                                    }
                                    partCarTripOutput.setEndhighvoltagetime(DateUtil.date(carTripStartWithQuitReadySeconedValueState.value().getItem_time()).toString());
                                    partCarTripOutput.setIpvehtotdistance(NumberUtil.sub(partCarTripOutput.getEndipvehtotdistance(), partCarTripOutput.getStartipvehtotdistance()));
                                    //退出行程主题
                                    //FIXME 清理状态
                                    //FIXME 基础性配置
                                    partTripTopicValueState.clear();
                                    pauseTripTopicValueState.clear();
                                    partCarTripOutputValueState.clear();
                                    //totalTripSpeedTopicValueState.clear();
                                    partTripSpeedTopicValueState.clear();
                                    //totalCarTripOutputValueState.clear();
                                    //FIXME 首次ready等亮起
                                    //readyStatusValueState.clear();
                                    //readyStartTimeValueState.clear();
                                    //carTripStartWithReadyValueState.clear();
                                    //FIXME 首次速度大于等于2
                                    speedStartStatusValueState.clear();
                                    speedStartTimeValueState.clear();
                                    //carTripStartWithSpeedValueState.clear();
                                    //FIXME 最后一次ready等亮起
                                    //quitReadyStatusValueState.clear();
                                    //quitReadyStartTimeValueState.clear();
                                    //carTripStartWithQuitReadyValueState.clear();
                                    //FIXME 其他
                                    carTripEndWithReadyValueState.clear();
                                    //carTripSpeedFirstZeroValueState.clear();
                                    //carTripSpeedLastZeroValueState.clear();
                                    partTripDurationTimeValueState.clear();
                                    carTripUpStartWithQuitReadyValueState.clear();
                                    carTripOutputList.add(partCarTripOutput);
                                }
                                //totalCarTripOutput
                                CarTripOutput totalCarTripOutput = totalCarTripOutputValueState.value();
                                totalCarTripOutput = constructCarTripEndData(carTripStartWithQuitReadySeconedValueState.value(), totalCarTripOutput);
                                if (ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())) {
                                    totalCarTripOutput = constructCarTripEndData(carTripEndWithSpeedSeconedValueState.value(), totalCarTripOutput);
                                    totalCarTripOutput.setEndbmssoc(null);
                                    totalCarTripOutput.setEndbmssoe(null);
                                    totalCarTripOutput.setEndbmssoh(null);
                                    totalCarTripOutput.setEndbmsmoduletempmax(null);
                                    totalCarTripOutput.setEndbmsmoduletempmin(null);
                                    totalCarTripOutput.setEndbmsmoduletempaverage(null);
                                    totalCarTripOutput.setEndincartemp(null);
                                    totalCarTripOutput.setIpvehtotdistance(null);
                                }
                                if (ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())&&ObjectUtil.isNotEmpty(totalCarTripOutput.getTripstarttime())) {
                                    totalCarTripOutput.setTripendtime(DateUtil.date(carTripEndWithSpeedSeconedValueState.value().getItem_time()).toString());
                                    totalCarTripOutput.setEndbmssoc(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOC(),0d));
                                    totalCarTripOutput.setEndbmssoe(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOE(),0d));
                                    totalCarTripOutput.setEndbmssoh(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getBMS_SOH(),0d));
                                    totalCarTripOutput.setEndbmsmoduletempmax(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMax());
                                    totalCarTripOutput.setEndbmsmoduletempmin(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMin());
                                    totalCarTripOutput.setEndbmsmoduletempaverage(carTripEndWithSpeedSeconedValueState.value().getBMS_RMC_ModuleTempMin());
                                    totalCarTripOutput.setEndincartemp(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getInCarTemp(),0d));
                                    totalCarTripOutput.setTripflag(tripGlagValueState.value());
                                    //经纬度判断2km/5分钟内
                                    if(ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value().getLatitude())&&carTripEndWithSpeedSeconedValueState.value().getLatitude().compareTo(Convert.toBigDecimal(INVALID_PARAMETER)) != 0) {
                                        totalCarTripOutput.setEndlatitude(carTripEndWithSpeedSeconedValueState.value().getLatitude());
                                        totalCarTripOutput.setEndlongitude(carTripEndWithSpeedSeconedValueState.value().getLongitude());
                                        totalCarTripOutput.setGpsflag("1");
                                        //System.out.println("原始值更新");
                                    }else if (ObjectUtil.isNotEmpty(endTripGpsValueState.value())&&ObjectUtil.isNotEmpty(endTripGpsValueState.value().getItem_time())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value().getItem_time())){
                                        if(countDuration(DateUtil.date(endTripGpsValueState.value().getItem_time()),DateUtil.date(carTripEndWithSpeedSeconedValueState.value().getItem_time()) ) > 300) {
                                            totalCarTripOutput.setEndlatitude(endTripGpsValueState.value().getLatitude());
                                            totalCarTripOutput.setEndlongitude(endTripGpsValueState.value().getLongitude());
                                            //System.out.println("最新值更新");
                                            if (ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState)&&ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value()) && totalTripSpeedTopicValueState.value()) {
                                                totalCarTripOutput.setGpsflag("0");
                                            } else {
                                                totalCarTripOutput.setGpsflag("1");
                                            }
                                        }
                                    }else if (ObjectUtil.isNotEmpty(endTripGpsValueState.value())&&ObjectUtil.isNotEmpty(endTripGpsValueState.value().getIP_VehTotDistance())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance())){
                                        if(countDuration(Convert.toLong(endTripGpsValueState.value().getIP_VehTotDistance()),Convert.toLong(carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance())) > 2L) {
                                            totalCarTripOutput.setEndlatitude(endTripGpsValueState.value().getLatitude());
                                            totalCarTripOutput.setEndlongitude(endTripGpsValueState.value().getLongitude());
                                            //System.out.println("最新值更新");
                                            if (ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState)&&ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value()) && totalTripSpeedTopicValueState.value()) {
                                                totalCarTripOutput.setGpsflag("0");
                                            } else {
                                                totalCarTripOutput.setGpsflag("1");
                                            }
                                        }
                                    } else{
                                        totalCarTripOutput.setGpsflag("0");
                                    }
                                    if(ObjectUtil.isNotEmpty(totalTripDurationTimeValueState.value())) {
                                        totalCarTripOutput.setTripduration(totalTripDurationTimeValueState.value().toString());
                                    }
                                    if(carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance()==INVALID_PARAMETER){
                                        totalCarTripOutput.setEndipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                                    }
                                    else {
                                        totalCarTripOutput.setEndipvehtotdistance(Convert.toDouble(carTripEndWithSpeedSeconedValueState.value().getIP_VehTotDistance(),0d));
                                    }
                                }
                                if(ObjectUtil.isNotEmpty(totalCarTripOutput.getDeviceId())&&ObjectUtil.isNotEmpty(totalCarTripOutput.getTripendtime())) {
                                    UpTrip upTripEnd = new UpTrip();
                                    upTripEnd.setDeviceId(totalCarTripOutput.getDeviceId());
                                    upTripEnd.setItem_time(totalCarTripOutput.getTripendtime());
                                    upTripEnd.setArea(totalCarTripOutput.getStartarea());
                                    upTripEnd.setModel_code(totalCarTripOutput.getModel_code());
                                    upTripEnd.setVehicletype(totalCarTripOutput.getVehicletype());
                                    upTripEnd.setBms_swversion(totalCarTripOutput.getBms_swversion());
                                    upTripEnd.setFlag("0");
                                    upTripEnd.setGpsflag(totalCarTripOutput.getGpsflag());
                                    String upTripEndJson = JSONUtil.toJsonStr(upTripEnd);
                                    //行程结束推送充电主题数据
                                    //System.out.println("redis搞起来");
                                    JedisCluster jedisCluster = RedisClient.jedisCluster;
                                    jedisCluster.rpush("DWM_TRIP_TOTAL"+upTripEnd.getDeviceId(),upTripEndJson);
                                    //System.out.println(upTripEndJson);
                                    //KafkaUtils.sendMessage("dwm_clean_trip", upTripEndJson);
                                }
                                //获取地区码
                                Map<String, String> code = SupplyUtil.supplyCode(carTripStartWithQuitReadySeconedValueState.value().getLatitude(), carTripStartWithQuitReadySeconedValueState.value().getLongitude());
                                if (ObjectUtil.isNotEmpty(code)){
                                    totalCarTripOutput.setEndarea(code.get("adCode"));
                                    totalCarTripOutput.setEndpoi(code.get("poiType"));
                                    endAdCodeValueState.update(code.get("adCode"));
                                }
                                if (ObjectUtil.isNotEmpty(totalCarTripOutput.getStartarea()) && ObjectUtil.isNotEmpty(totalCarTripOutput.getEndarea())) {
                                    if (StrUtil.sub(totalCarTripOutput.getStartarea(), 0, 4).equals(StrUtil.sub(totalCarTripOutput.getEndarea(), 0, 4))) {
                                        totalCarTripOutput.setTravelrange(0);
                                    } else if (StrUtil.sub(totalCarTripOutput.getStartarea(), 0, 2).equals(StrUtil.sub(totalCarTripOutput.getEndarea(), 0, 2))) {
                                        totalCarTripOutput.setTravelrange(1);
                                    }else {
                                        totalCarTripOutput.setTravelrange(2);
                                    }
                                }
                                totalCarTripOutput.setEndhighvoltagetime(DateUtil.date(carTripStartWithQuitReadySeconedValueState.value().getItem_time()).toString());

                                //FIXME 存在行程开始时间未能满足的情况，以上高压时间替代
                                if (ObjectUtil.isEmpty(totalCarTripOutput.getTripstarttime())) {
                                    totalCarTripOutput.setTripno(-1);
                                    totalCarTripNoValueState.update(totalCarTripNoValueState.value() - 1);
                                }
                                totalCarTripOutput.setIpvehtotdistance(NumberUtil.sub(totalCarTripOutput.getEndipvehtotdistance(), totalCarTripOutput.getStartipvehtotdistance()));
                                if (ObjectUtil.isEmpty(carTripEndWithSpeedSeconedValueState.value())) {
                                    totalCarTripOutput.setEndbmssoc(null);
                                    totalCarTripOutput.setEndbmssoe(null);
                                    totalCarTripOutput.setEndbmssoh(null);
                                    totalCarTripOutput.setEndbmsmoduletempmax(null);
                                    totalCarTripOutput.setEndbmsmoduletempmin(null);
                                    totalCarTripOutput.setEndbmsmoduletempaverage(null);
                                    totalCarTripOutput.setEndincartemp(null);
                                }


                                //FIXME 清理状态
                                //FIXME 基础性配置
                                if(duration1>=1) {
                                    totalCarTripNoValueState.clear();
                                }
                                tripDateValueState.clear();
                                totalTripTopicValueState.clear();
                                partTripTopicValueState.clear();
                                pauseTripTopicValueState.clear();
                                totalTripSpeedTopicValueState.clear();
                                partTripSpeedTopicValueState.clear();
                                totalCarTripOutputValueState.clear();
                                partCarTripOutputValueState.clear();
                                //FIXME 首次ready等亮起
                                //readyStatusValueState.clear();
                                //readyStartTimeValueState.clear();
                                //carTripStartWithReadyValueState.clear();
                                //FIXME 速度大于等于2
                                speedStartStatusValueState.clear();
                                speedStartTimeValueState.clear();
                                //carTripStartWithSpeedValueState.clear();
                                //FIXME 速度小于2
                                speedEndStatusValueState.clear();
                                speedEndTimeValueState.clear();
                                carTripEndWithSpeedValueState.clear();
                                carTripEndReadyWithSpeedValueState.clear();
                                //FIXME 最后一次ready等亮起
                                quitReadyStatusValueState.clear();
                                quitReadyStartTimeValueState.clear();
                                carTripStartWithQuitReadyValueState.clear();
                                //FIXME 其他
                                carTriptotalStartWithQuitReadyValueState.clear();
                                carTripEndWithReadyValueState.clear();
                                //carTripSpeedFirstZeroValueState.clear();
                                //carTripSpeedLastZeroValueState.clear();
                                carTripStartWithQuitReadyTimeValueState.clear();
                                carTriptotalStartWithQuitReadyTimeValueState.clear();
                                //carTripStartWithQuitReadySeconedValueState.clear();
                                carTripEndWithSpeedSeconedValueState.clear();
                                totalTripDurationTimeValueState.clear();
                                partTripDurationTimeValueState.clear();
                                carTripUpStartWithQuitReadyValueState.clear();
                                tripGlagValueState.clear();

                                //FIXME 初始化衔接
                                //速度大于等于2
                                if(carTripStartWithReadyValueState.value().getItem_time()<carTripStartWithQuitReadySeconedValueState.value().getItem_time()){
                                    readyStatusValueState.clear();
                                    readyStartTimeValueState.clear();
                                    carTripStartWithReadyValueState.clear();
                                    carTripStartWithSpeedValueState.clear();
                                    carTripSpeedFirstZeroValueState.clear();
                                    carTripSpeedLastZeroValueState.clear();
                                    carTripStartWithQuitReadySeconedValueState.clear();
                                    if (Convert.toInt(carTrip.getVehSpd()) >= CurrentVelocityThreshold) {
                                        if (ObjectUtil.isEmpty(carTripStartWithSpeedValueState.value())) {
                                            carTripStartWithSpeedValueState.update(carTrip);
                                        }
                                    }
                                    //速度小于2
                                    if (carTrip.getVCU_RdyLEDSts_RM() == READY_LED_STATUS && Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold) {
                                        //存在最新一条速度<2的行程数据
                                        if (ObjectUtil.isEmpty(carTripSpeedFirstZeroValueState.value())) {
                                            carTripSpeedFirstZeroValueState.update(carTrip);
                                        }
                                        carTripSpeedLastZeroValueState.update(carTrip);
                                    }
                                    //首次进入稳态
                                    if (ObjectUtil.isEmpty(readyStatusValueState.value()) || !readyStatusValueState.value()) {
                                        readyStatusValueState.update(true);
                                        readyStartTimeValueState.update(DateUtil.date(carTrip.getItem_time()));
                                        carTripStartWithReadyValueState.update(carTrip);
                                        //System.out.println(StrUtil.format("carTripStartWithReadyValueState.value().getItem_time():{}————--行程开始时间[00]---", DateUtil.date(Convert.toDate(carTripStartWithReadyValueState.value().getItem_time()))));
                                    }
                                }
                                carTripOutputList.add(totalCarTripOutput);
                                return carTripOutputList;
                            }
                        }
                    }
                }
                //状态值为1开始断点==========================end

                //FIXME 已进入稳态（持续性）
                if (ObjectUtil.isNotEmpty(readyStatusValueState.value()) || readyStatusValueState.value()) {
                    long duration = countDuration(DateUtil.date(readyStartTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));
                    if (duration >= SteadyStateDuration) {
                        quitReadyStatusValueState.clear();
                        quitReadyStartTimeValueState.clear();
                        if (ObjectUtil.isEmpty(totalTripTopicValueState.value())) {
                            totalTripTopicValueState.update(true);
                            //System.err.println(StrUtil.format("VIN:{}————TIME:{}————ACTION:{}————DATA:{}", carTrip.getDeviceId(), DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()), "开启总行程", JSONUtil.parse(carTripStartWithReadyValueState.value())));
                        }

                        if (ObjectUtil.isEmpty(partTripTopicValueState.value())) {
                            partTripTopicValueState.update(true);
                            //System.err.println(StrUtil.format("VIN:{}————TIME:{}————ACTION:{}————DATA:{}", carTrip.getDeviceId(), DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()), "开启子行程", JSONUtil.parse(carTripStartWithReadyValueState.value())));
                        }
                        //为还在大行程主题，但是下一条数据跨时间段特别长的做准备数据
                        if(ObjectUtil.isNotEmpty(carTripStartWithQuitReadyValueState.value())&&ObjectUtil.isNotEmpty(partTripTopicValueState.value())){
                            carTripStartWithQuitReadySeconedValueState.update(carTripStartWithQuitReadyValueState.value());
                        }
                        //持续修改，后续调用时即认为最后一条ready灯亮起的数据
                        if(ObjectUtil.isNotEmpty(partTripTopicValueState.value())) {
                            carTriptotalStartWithQuitReadyValueState.update(carTrip);
                            carTriptotalStartWithQuitReadyTimeValueState.update(DateUtil.date(carTrip.getItem_time()));
                        }
                    }
                }
            }

            //FIXME 当前数据Ready灯灭 进入退出稳态
            if (carTrip.getVCU_RdyLEDSts_RM() != READY_LED_STATUS) {
                //首次进入退出稳态
                if (ObjectUtil.isEmpty(quitReadyStatusValueState.value()) || !quitReadyStatusValueState.value()) {
                    quitReadyStatusValueState.update(true);
                    quitReadyStartTimeValueState.update(DateUtil.date(carTrip.getItem_time()));
                    carTripStartWithQuitReadyTimeValueState.update(DateUtil.date(carTrip.getItem_time()));
                }
                if (ObjectUtil.isEmpty(totalTripTopicValueState.value()) || ObjectUtil.isEmpty(partTripTopicValueState.value())) {
                    readyStatusValueState.clear();
                    readyStartTimeValueState.clear();
                    carTripStartWithReadyValueState.clear();
                    speedStartStatusValueState.clear();
                    speedStartTimeValueState.clear();
                    carTripStartWithSpeedValueState.clear();
                    carTripSpeedFirstZeroValueState.clear();
                }
                if(ObjectUtil.isEmpty(partTripSpeedTopicValueState.value())&&ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value())&&Convert.toInt(carTrip.getVehSpd()) < CurrentVelocityThreshold){
                    speedStartStatusValueState.clear();
                    speedStartTimeValueState.clear();
                    carTripStartWithSpeedValueState.clear();
                }

                //FIXME 持续速度小于2判断
                //持续进入退出稳态
                if ((ObjectUtil.isNotEmpty(quitReadyStatusValueState.value()) || quitReadyStatusValueState.value())&&ObjectUtil.isNotEmpty(carTriptotalStartWithQuitReadyTimeValueState.value())) {
                    long duration1 = countDuration(DateUtil.date(carTriptotalStartWithQuitReadyTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));
                    long duration = countDuration(DateUtil.date(quitReadyStartTimeValueState.value()), DateUtil.date(carTrip.getItem_time()));

                    //TODO 退出稳态持续达到60S 退出小行程 || duration1 > ApplicationSetting.getSteadyStateDuration()
                    if (duration >= SteadyStateDuration || duration1 >= TripTimeoutDuration) {
                        if (ObjectUtil.isNotEmpty(partTripTopicValueState.value())) {
                            //记录子行程结束
                            CarTripOutput partCarTripOutput = partCarTripOutputValueState.value();
                            if(ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())) {
                                if(carTripEndWithSpeedValueState.value().getItem_time()> carTripStartWithQuitReadyValueState.value().getItem_time()){
                                    if(ObjectUtil.isNotEmpty(carTripEndReadyWithSpeedValueState.value())) {
                                        carTripEndWithSpeedValueState.update(carTripEndReadyWithSpeedValueState.value());
                                    }
                                }
                                partCarTripOutput = constructCarTripEndData(carTripEndWithSpeedValueState.value(), partCarTripOutput);
                                partCarTripOutput.setEndbmssoc(null);
                                partCarTripOutput.setEndbmssoe(null);
                                partCarTripOutput.setEndbmssoh(null);
                                partCarTripOutput.setEndbmsmoduletempmax(null);
                                partCarTripOutput.setEndbmsmoduletempmin(null);
                                partCarTripOutput.setEndbmsmoduletempaverage(null);
                                partCarTripOutput.setEndincartemp(null);
                                partCarTripOutput.setIpvehtotdistance(null);
                            }
                            if (ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())) {
                                Boolean timeBefore = DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).isBefore(DateUtil.date(carTripEndWithSpeedValueState.value().getItem_time()));
                                if (timeBefore) {
                                    partCarTripOutput.setTripendtime(DateUtil.date(carTripEndWithSpeedValueState.value().getItem_time()).toString());
                                    partCarTripOutput.setEndbmssoc(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOC(),0d));
                                    partCarTripOutput.setEndbmssoe(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOE(),0d));
                                    partCarTripOutput.setEndbmssoh(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOH(),0d));
                                    partCarTripOutput.setEndbmsmoduletempmax(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMax());
                                    partCarTripOutput.setEndbmsmoduletempmin(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                                    partCarTripOutput.setEndbmsmoduletempaverage(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                                    partCarTripOutput.setEndincartemp(Convert.toDouble(carTripEndWithSpeedValueState.value().getInCarTemp(),0d));
                                    if(carTripEndWithSpeedValueState.value().getIP_VehTotDistance()==INVALID_PARAMETER){
                                        partCarTripOutput.setEndipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                                    }
                                    else {
                                        partCarTripOutput.setEndipvehtotdistance(Convert.toDouble(carTripEndWithSpeedValueState.value().getIP_VehTotDistance(),0d));
                                    }
                                }
                            }
                            partCarTripOutput.setEndhighvoltagetime(DateUtil.date(carTripStartWithQuitReadyValueState.value().getItem_time()).toString());
                            partCarTripOutput.setIpvehtotdistance(NumberUtil.sub(partCarTripOutput.getEndipvehtotdistance(), partCarTripOutput.getStartipvehtotdistance()));
                            //大行程累加时间
                            if(ObjectUtil.isNotEmpty(speedStartTimeValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value().getItem_time())) {
                                if(ObjectUtil.isEmpty(totalTripDurationTimeValueState.value())){
                                    totalTripDurationTimeValueState.update(0L);
                                }
                                if(ObjectUtil.isEmpty(partTripDurationTimeValueState.value())){
                                    partTripDurationTimeValueState.update(0L);
                                }
                                //System.out.println(StrUtil.format("speedStartTimeValueState.value():{}————--行程开始时间[4]---", speedStartTimeValueState.value()));
                                //System.out.println(StrUtil.format("carTripEndWithSpeedValueState.value().getItem_time():{}————--行程结束时间[4]---", DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                totalTripDurationTimeValueState.update(totalTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(speedStartTimeValueState.value())), DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                partTripDurationTimeValueState.update(partTripDurationTimeValueState.value() + countDuration(DateUtil.date(Convert.toDate(speedStartTimeValueState.value())), DateUtil.date(Convert.toDate(carTripEndWithSpeedValueState.value().getItem_time()))));
                                //System.out.println(StrUtil.format("partTripDurationTimeValueState:{}————--行程时间为[4]---", partTripDurationTimeValueState.value()));
                                //System.out.println(StrUtil.format("totalTripDurationTimeValueState:{}————--行程时间为[4]---", totalTripDurationTimeValueState.value()));
                                //System.out.println(StrUtil.format("VIN:{}————--行程时间为[4]---", totalTripDurationTimeValueState.value()));
                            }
                            if(ObjectUtil.isNotEmpty(partTripDurationTimeValueState.value())) {
                                partCarTripOutput.setTripduration(partTripDurationTimeValueState.value().toString());
                            }
                            //退出行程主题
                            //FIXME 清理状态
                            //FIXME 基础性配置
                            partTripTopicValueState.clear();
                            pauseTripTopicValueState.clear();
                            partCarTripOutputValueState.clear();
                            //totalTripSpeedTopicValueState.clear();
                            partTripSpeedTopicValueState.clear();
                            //totalCarTripOutputValueState.clear();
                            //FIXME 首次ready等亮起
                            readyStatusValueState.clear();
                            readyStartTimeValueState.clear();
                            carTripStartWithReadyValueState.clear();
                            //FIXME 首次速度大于等于2
                            speedStartStatusValueState.clear();
                            speedStartTimeValueState.clear();
                            carTripStartWithSpeedValueState.clear();
                            //FIXME 最后一次速度大于2
                            //speedEndStatusValueState.clear();
                            //speedEndTimeValueState.clear();
                            //carTripEndWithSpeedValueState.clear();
                            //FIXME 最后一次ready等亮起
                            quitReadyStatusValueState.clear();
                            quitReadyStartTimeValueState.clear();
                            //carTripStartWithQuitReadyValueState.clear();

                            //FIXME 其他
                            carTripEndWithReadyValueState.clear();
                            carTripSpeedFirstZeroValueState.clear();
                            carTripSpeedLastZeroValueState.clear();
                            partTripDurationTimeValueState.clear();
                            carTripUpStartWithQuitReadyValueState.clear();
                            carTripOutputList.add(partCarTripOutput);
                            return carTripOutputList;
                        }
                    }


                    //TODO 退出稳态持续达到900S 退出大行程
                    if (duration1 >= TripTimeoutDuration) {
                        if (ObjectUtil.isNotEmpty(totalTripTopicValueState.value())) {
                            long duration3 = DateUtil.between(DateUtil.beginOfDay(tripDateValueState.value()), DateUtil.beginOfDay(DateUtil.date(carTrip.getItem_time())), DateUnit.DAY);

                            //System.err.println(StrUtil.format("VIN:{}————TIME:{}————ACTION:{}————DATA:{}", carTrip.getDeviceId(), DateUtil.date(carTripEndWithSpeedValueState.value().getItem_time()), "退出总行程(TripEndTime)", JSONUtil.parse(carTripEndWithSpeedValueState.value())));

                            CarTripOutput totalCarTripOutput = totalCarTripOutputValueState.value();
                            totalCarTripOutput = constructCarTripEndData(carTripStartWithQuitReadyValueState.value(), totalCarTripOutput);
                            if(ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())) {
                                if(carTripEndWithSpeedValueState.value().getItem_time()> carTripStartWithQuitReadyValueState.value().getItem_time()){
                                    if(ObjectUtil.isNotEmpty(carTripEndReadyWithSpeedValueState.value())) {
                                        carTripEndWithSpeedValueState.update(carTripEndReadyWithSpeedValueState.value());
                                    }
                                }
                                totalCarTripOutput = constructCarTripEndData(carTripEndWithSpeedValueState.value(), totalCarTripOutput);
                                totalCarTripOutput.setEndbmssoc(null);
                                totalCarTripOutput.setEndbmssoe(null);
                                totalCarTripOutput.setEndbmssoh(null);
                                totalCarTripOutput.setEndbmsmoduletempmax(null);
                                totalCarTripOutput.setEndbmsmoduletempmin(null);
                                totalCarTripOutput.setEndbmsmoduletempaverage(null);
                                totalCarTripOutput.setEndincartemp(null);
                                totalCarTripOutput.setIpvehtotdistance(null);
                            }
                            if (ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(totalCarTripOutput.getTripstarttime())) {
                                totalCarTripOutput.setTripendtime(DateUtil.date(carTripEndWithSpeedValueState.value().getItem_time()).toString());
                                totalCarTripOutput.setEndbmssoc(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOC(),0d));
                                totalCarTripOutput.setEndbmssoe(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOE(),0d));
                                totalCarTripOutput.setEndbmssoh(Convert.toDouble(carTripEndWithSpeedValueState.value().getBMS_SOH(),0d));
                                totalCarTripOutput.setEndbmsmoduletempmax(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMax());
                                totalCarTripOutput.setEndbmsmoduletempmin(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                                totalCarTripOutput.setEndbmsmoduletempaverage(carTripEndWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                                totalCarTripOutput.setEndincartemp(Convert.toDouble(carTripEndWithSpeedValueState.value().getInCarTemp(),0d));
                                totalCarTripOutput.setTripflag(tripGlagValueState.value());
                                //经纬度判断2km/5分钟内
                                if(ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value().getLatitude())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&carTripEndWithSpeedValueState.value().getLatitude().compareTo(Convert.toBigDecimal(INVALID_PARAMETER)) != 0) {
                                    totalCarTripOutput.setEndlatitude(carTripEndWithSpeedValueState.value().getLatitude());
                                    totalCarTripOutput.setEndlongitude(carTripEndWithSpeedValueState.value().getLongitude());
                                    totalCarTripOutput.setGpsflag("1");
                                    //System.out.println("原始值更新");
                                } else if (ObjectUtil.isNotEmpty(endTripGpsValueState.value())&&ObjectUtil.isNotEmpty(endTripGpsValueState.value().getItem_time())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value().getItem_time())){
                                    if(countDuration(DateUtil.date(endTripGpsValueState.value().getItem_time()),DateUtil.date(carTripEndWithSpeedValueState.value().getItem_time()) ) > 300) {
                                        totalCarTripOutput.setEndlatitude(endTripGpsValueState.value().getLatitude());
                                        totalCarTripOutput.setEndlongitude(endTripGpsValueState.value().getLongitude());
                                        //System.out.println("最新值更新");
                                        if (ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState) &&ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value()) && totalTripSpeedTopicValueState.value()) {
                                            totalCarTripOutput.setGpsflag("0");
                                        } else {
                                            totalCarTripOutput.setGpsflag("1");
                                        }
                                    }
                                }else if (ObjectUtil.isNotEmpty(endTripGpsValueState.value())&&ObjectUtil.isNotEmpty(endTripGpsValueState.value().getIP_VehTotDistance())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(carTripEndWithSpeedValueState.value().getIP_VehTotDistance())){
                                    if(countDuration(Convert.toLong(endTripGpsValueState.value().getIP_VehTotDistance()),Convert.toLong(carTripEndWithSpeedValueState.value().getIP_VehTotDistance())) > 2L) {
                                        totalCarTripOutput.setEndlatitude(endTripGpsValueState.value().getLatitude());
                                        totalCarTripOutput.setEndlongitude(endTripGpsValueState.value().getLongitude());
                                        //System.out.println("最新值更新");
                                        if (ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState) &&ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value()) && totalTripSpeedTopicValueState.value()) {
                                            totalCarTripOutput.setGpsflag("0");
                                        } else {
                                            totalCarTripOutput.setGpsflag("1");
                                        }
                                    }
                                } else {
                                    totalCarTripOutput.setGpsflag("0");
                                }
                                if(ObjectUtil.isNotEmpty(totalTripDurationTimeValueState.value())) {
                                    totalCarTripOutput.setTripduration(totalTripDurationTimeValueState.value().toString());
                                }
                                if(carTripEndWithSpeedValueState.value().getIP_VehTotDistance()==INVALID_PARAMETER){
                                    totalCarTripOutput.setEndipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                                }
                                else {
                                    totalCarTripOutput.setEndipvehtotdistance(Convert.toDouble(carTripEndWithSpeedValueState.value().getIP_VehTotDistance(),0d));
                                }
                            }
                            if(ObjectUtil.isNotEmpty(totalCarTripOutput.getDeviceId())&&ObjectUtil.isNotEmpty(totalCarTripOutput.getTripendtime())) {
                                UpTrip upTripEnd = new UpTrip();
                                upTripEnd.setDeviceId(totalCarTripOutput.getDeviceId());
                                upTripEnd.setItem_time(totalCarTripOutput.getTripendtime());
                                upTripEnd.setArea(totalCarTripOutput.getStartarea());
                                upTripEnd.setModel_code(totalCarTripOutput.getModel_code());
                                upTripEnd.setVehicletype(totalCarTripOutput.getVehicletype());
                                upTripEnd.setBms_swversion(totalCarTripOutput.getBms_swversion());
                                upTripEnd.setFlag("0");
                                upTripEnd.setGpsflag(totalCarTripOutput.getGpsflag());
                                String upTripEndJson = JSONUtil.toJsonStr(upTripEnd);
                                //System.out.println("redis搞起来");
                                JedisCluster jedisCluster = RedisClient.jedisCluster;
                                jedisCluster.rpush("DWM_TRIP_TOTAL"+upTripEnd.getDeviceId(),upTripEndJson);
                                //System.out.println(upTripEndJson);
                                //KafkaUtils.sendMessage("dwm_clean_trip", upTripEndJson);
                            }
                            //获取地区码
                            Map<String, String> code = SupplyUtil.supplyCode(carTriptotalStartWithQuitReadyValueState.value().getLatitude(), carTriptotalStartWithQuitReadyValueState.value().getLongitude());
                            if (ObjectUtil.isNotEmpty(code)){
                                totalCarTripOutput.setEndarea(code.get("adCode"));
                                totalCarTripOutput.setEndpoi(code.get("poiType"));
                                endAdCodeValueState.update(totalCarTripOutput.getEndarea());
                            }
                            if (ObjectUtil.isNotEmpty(totalCarTripOutput.getStartarea()) && ObjectUtil.isNotEmpty(totalCarTripOutput.getEndarea())) {
                                if (StrUtil.sub(totalCarTripOutput.getStartarea(), 0, 4).equals(StrUtil.sub(totalCarTripOutput.getEndarea(), 0, 4))) {
                                    totalCarTripOutput.setTravelrange(0);
                                } else if (StrUtil.sub(totalCarTripOutput.getStartarea(), 0, 2).equals(StrUtil.sub(totalCarTripOutput.getEndarea(), 0, 2))) {
                                    totalCarTripOutput.setTravelrange(1);
                                }else {
                                    totalCarTripOutput.setTravelrange(2);
                                }
                            }
                            totalCarTripOutput.setEndhighvoltagetime(DateUtil.date(carTriptotalStartWithQuitReadyValueState.value().getItem_time()).toString());
                            //FIXME 存在行程开始时间未能满足的情况，以上高压时间替代
                            if (ObjectUtil.isEmpty(totalCarTripOutput.getTripstarttime())) {
                                totalCarTripOutput.setTripno(-1);
                                totalCarTripNoValueState.update(totalCarTripNoValueState.value() - 1);
                            }
                            totalCarTripOutput.setIpvehtotdistance(NumberUtil.sub(totalCarTripOutput.getEndipvehtotdistance(), totalCarTripOutput.getStartipvehtotdistance()));
                            if (ObjectUtil.isEmpty(carTripEndWithSpeedValueState.value())) {
                                totalCarTripOutput.setEndbmssoc(null);
                                totalCarTripOutput.setEndbmssoe(null);
                                totalCarTripOutput.setEndbmssoh(null);
                                totalCarTripOutput.setEndbmsmoduletempmax(null);
                                totalCarTripOutput.setEndbmsmoduletempmin(null);
                                totalCarTripOutput.setEndbmsmoduletempaverage(null);
                                totalCarTripOutput.setEndincartemp(null);
                                //totalCarTripOutput.setIpvehtotdistance(null);
                            }

                            //FIXME 清理状态
                            //FIXME 基础性配置
                            if(duration3>=1) {
                                totalCarTripNoValueState.clear();
                            }
                            tripDateValueState.clear();
                            totalTripTopicValueState.clear();
                            partTripTopicValueState.clear();
                            pauseTripTopicValueState.clear();
                            totalTripSpeedTopicValueState.clear();
                            partTripSpeedTopicValueState.clear();
                            totalCarTripOutputValueState.clear();
                            partCarTripOutputValueState.clear();
                            //FIXME 首次ready等亮起
                            readyStatusValueState.clear();
                            readyStartTimeValueState.clear();
                            carTripStartWithReadyValueState.clear();
                            //FIXME 首次速度大于等于2
                            speedStartStatusValueState.clear();
                            speedStartTimeValueState.clear();
                            carTripStartWithSpeedValueState.clear();
                            //FIXME 最后一次速度大于2
                            speedEndStatusValueState.clear();
                            speedEndTimeValueState.clear();
                            carTripEndWithSpeedValueState.clear();
                            carTripEndReadyWithSpeedValueState.clear();
                            //FIXME 最后一次ready等亮起
                            quitReadyStatusValueState.clear();
                            quitReadyStartTimeValueState.clear();
                            carTripStartWithQuitReadyValueState.clear();
                            //FIXME 其他
                            carTriptotalStartWithQuitReadyTimeValueState.clear();
                            carTripEndWithReadyValueState.clear();
                            carTripSpeedFirstZeroValueState.clear();
                            carTripSpeedLastZeroValueState.clear();
                            carTripStartWithQuitReadyTimeValueState.clear();
                            totalTripDurationTimeValueState.clear();
                            partTripDurationTimeValueState.clear();
                            carTripUpStartWithQuitReadyValueState.clear();
                            tripGlagValueState.clear();

                            carTripOutputList.add(totalCarTripOutput);
                            return carTripOutputList;
                        }
                    }
                }
            }

            //FIXME 开启总行程（上高压）
            if (ObjectUtil.isNotEmpty(totalTripTopicValueState.value()) && ObjectUtil.isEmpty(totalCarTripOutputValueState.value())) {
                //FIXME 更新行程编号
                if (ObjectUtil.isEmpty(totalCarTripNoValueState.value())) {
                    totalCarTripNoValueState.update(1);
                } else {
                    totalCarTripNoValueState.update(totalCarTripNoValueState.value() + 1);
                }

                //构造总行程开始数据
                CarTripOutput carTripOutput = new CarTripOutput(CarTripOutput.TOTAL_TRIP);
                carTripOutput.setTripno(totalCarTripNoValueState.value());
                carTripOutput.setStarthighvoltagetime(DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).toString());
                carTripOutput.setTripstartdate(DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).toString("YYYY-MM-dd"));
                carTripOutput = constructCarTripStartData(carTrip, carTripOutput);
                carTripOutput.setStartbmssoc(null);
                carTripOutput.setStartbmssoe(null);
                carTripOutput.setStartbmssoh(null);
                carTripOutput.setStartbmsmoduletempmax(null);
                carTripOutput.setStartbmsmoduletempmin(null);
                carTripOutput.setStartbmsmoduletempaverage(null);
                carTripOutput.setStartincartemp(null);
                carTripOutput.setStartlatitude(carTripStartWithReadyValueState.value().getLatitude());
                carTripOutput.setStartlongitude(carTripStartWithReadyValueState.value().getLongitude());
                //行程开始获取地区码
                if(ObjectUtil.isNotEmpty(endAdCodeValueState.value())){
                    carTripOutput.setStartarea(endAdCodeValueState.value());
                }else {
                    Map<String, String> code = SupplyUtil.supplyCode(carTripOutput.getStartlatitude(), carTripOutput.getStartlongitude());
                    if (ObjectUtil.isNotEmpty(code)) {
                        carTripOutput.setStartarea(code.get("adCode"));
                        carTripOutput.setStartpoi(code.get("poiType"));
                    }
                }
                totalCarTripOutputValueState.update(carTripOutput);
                //System.err.println(StrUtil.format("VIN:{}————TIME:{}————ACTION:{}————DATA:{}", carTrip.getDeviceId(), carTripOutput.getStarthighvoltagetime(), "构造总行程开始数据（上高压）", JSONUtil.parse(carTripOutput)));
            }
            //FIXME 开启子行程（上高压）
            if (ObjectUtil.isNotEmpty(partTripTopicValueState.value()) && ObjectUtil.isEmpty(partCarTripOutputValueState.value())) {
                //构造子行程开始数据
                CarTripOutput carTripOutput = new CarTripOutput(CarTripOutput.PART_TRIP);
                carTripOutput.setStarthighvoltagetime(DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).toString());
                carTripOutput.setTripstartdate(DateUtil.date(carTripStartWithReadyValueState.value().getItem_time()).toString("YYYY-MM-dd"));
                carTripOutput = constructCarTripStartData(carTrip, carTripOutput);
                carTripOutput.setStartbmssoc(null);
                carTripOutput.setStartbmssoe(null);
                carTripOutput.setStartbmssoh(null);
                carTripOutput.setStartbmsmoduletempmax(null);
                carTripOutput.setStartbmsmoduletempmin(null);
                carTripOutput.setStartbmsmoduletempaverage(null);
                carTripOutput.setStartincartemp(null);
                carTripOutput.setStartlatitude(carTripStartWithReadyValueState.value().getLatitude());
                carTripOutput.setStartlongitude(carTripStartWithReadyValueState.value().getLongitude());
                partCarTripOutputValueState.update(carTripOutput);
            }
            //FIXME 根据速度决定是否开启总行程（tripStartTime）
            if (ObjectUtil.isNotEmpty(totalTripTopicValueState.value()) && ObjectUtil.isNotEmpty(totalCarTripOutputValueState.value().getDeviceId())) {
                //已具备速度判断条件
                if (ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(totalTripSpeedTopicValueState.value())) {
                    //TODO 当行程开始时间为空时写入
                    if (ObjectUtil.isEmpty(totalCarTripOutputValueState.value().getTripstarttime())) {
                        CarTripOutput totalCarTripOutput = totalCarTripOutputValueState.value();
                        if (ObjectUtil.isEmpty(totalCarTripOutput.getTripstarttime())) {
                            totalCarTripOutput.setTripstarttime(DateUtil.date(carTripStartWithSpeedValueState.value().getItem_time()).toString());
                            totalCarTripOutput.setStartbmssoc(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOC(),0d));
                            totalCarTripOutput.setStartbmssoe(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOE(),0d));
                            totalCarTripOutput.setStartbmssoh(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOH(),0d));
                            totalCarTripOutput.setStartbmsmoduletempmax(carTripStartWithSpeedValueState.value().getBMS_RMC_ModuleTempMax());
                            totalCarTripOutput.setStartbmsmoduletempmin(carTripStartWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                            totalCarTripOutput.setStartbmsmoduletempaverage(carTripStartWithSpeedValueState.value().getBMS_ModuleTempaverage());
                            totalCarTripOutput.setStartincartemp(Convert.toDouble(carTripStartWithSpeedValueState.value().getInCarTemp(),0d));
                            if(carTripStartWithSpeedValueState.value().getIP_VehTotDistance()==INVALID_PARAMETER){
                                totalCarTripOutput.setStartipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                            }
                            else {
                                totalCarTripOutput.setStartipvehtotdistance(Convert.toDouble(carTripStartWithSpeedValueState.value().getIP_VehTotDistance(), 0d));
                            }
                        }
                        if(ObjectUtil.isNotEmpty(totalCarTripOutput.getDeviceId())&&ObjectUtil.isNotEmpty(totalCarTripOutput.getTripstarttime())) {
                            UpTrip upTripStart = new UpTrip();
                            upTripStart.setDeviceId(totalCarTripOutput.getDeviceId());
                            upTripStart.setItem_time(totalCarTripOutput.getTripstarttime());
                            upTripStart.setArea(totalCarTripOutput.getStartarea());
                            upTripStart.setModel_code(totalCarTripOutput.getModel_code());
                            upTripStart.setVehicletype(totalCarTripOutput.getVehicletype());
                            upTripStart.setBms_swversion(totalCarTripOutput.getBms_swversion());
                            upTripStart.setFlag("1");
                            upTripStart.setGpsflag(totalCarTripOutput.getGpsflag());
                            String upTripStartJson = JSONUtil.toJsonStr(upTripStart);
                            //System.out.println(upTripStartJson);
                            //KafkaUtils.sendMessage("dwm_clean_trip", upTripStartJson);
                        }
                        totalCarTripOutputValueState.update(totalCarTripOutput);
                        //System.err.println(StrUtil.format("VIN:{}————TIME:{}————ACTION:{}————DATA:{}", carTrip.getDeviceId(), DateUtil.date(carTripStartWithSpeedValueState.value().getItem_time()), "更新子行程TripStartTime", JSONUtil.parse(carTripStartWithSpeedValueState.value())));
                    }
                }
            }
            //FIXME 根据速度决定是否开启子行程（tripStartTime）
            if (ObjectUtil.isNotEmpty(partTripTopicValueState.value()) && ObjectUtil.isNotEmpty(partCarTripOutputValueState.value().getDeviceId())) {
                if (ObjectUtil.isNotEmpty(carTripStartWithSpeedValueState.value())&&ObjectUtil.isNotEmpty(partTripSpeedTopicValueState.value())) {
                    //TODO 当行程开始时间为空时写入
                    if (ObjectUtil.isEmpty(partCarTripOutputValueState.value().getTripstarttime())) {
                        CarTripOutput partCarTripOutput = partCarTripOutputValueState.value();
                        if (ObjectUtil.isEmpty(partCarTripOutput.getTripstarttime())) {
                            partCarTripOutput.setTripstarttime(DateUtil.date(carTripStartWithSpeedValueState.value().getItem_time()).toString());
                            partCarTripOutput.setStartbmssoc(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOC(),0d));
                            partCarTripOutput.setStartbmssoe(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOE(),0d));
                            partCarTripOutput.setStartbmssoh(Convert.toDouble(carTripStartWithSpeedValueState.value().getBMS_SOH(),0d));
                            partCarTripOutput.setStartbmsmoduletempmax(carTripStartWithSpeedValueState.value().getBMS_RMC_ModuleTempMax());
                            partCarTripOutput.setStartbmsmoduletempmin(carTripStartWithSpeedValueState.value().getBMS_RMC_ModuleTempMin());
                            partCarTripOutput.setStartbmsmoduletempaverage(carTripStartWithSpeedValueState.value().getBMS_ModuleTempaverage());
                            partCarTripOutput.setStartincartemp(Convert.toDouble(carTripStartWithSpeedValueState.value().getInCarTemp(),0d));
                            if(carTripStartWithSpeedValueState.value().getIP_VehTotDistance()==INVALID_PARAMETER){
                                partCarTripOutput.setStartipvehtotdistance(Convert.toDouble(ipVehTotDistanceValueState.value(), 0d));
                            }
                            else {
                                partCarTripOutput.setStartipvehtotdistance(Convert.toDouble(carTripStartWithSpeedValueState.value().getIP_VehTotDistance(), 0d));
                            }
                        }
                        partCarTripOutputValueState.update(partCarTripOutput);
                    }
                }
            }
        }
        return carTripOutputList;
    }

    /**
     * 构造行程开始数据
     *
     * @param carTrip       当前流式数据
     * @param carTripOutput 行程记录数据
     * @return carTripOutput
     */
    public static CarTripOutput constructCarTripStartData (CarTrip carTrip, CarTripOutput carTripOutput){
        carTripOutput.setDeviceId(carTrip.getDeviceId());
        carTripOutput.setItem_time(carTrip.getItem_time());
        carTripOutput.setVehicletype(carTrip.getVehicletype());
        carTripOutput.setStartincartemp(Convert.toDouble(carTrip.getInCarTemp(), 0d));
        carTripOutput.setStartbmsmoduletempmax(carTrip.getBMS_RMC_ModuleTempMax());
        carTripOutput.setStartbmsmoduletempaverage(carTrip.getBMS_ModuleTempaverage());
        carTripOutput.setStartbmsmoduletempmin(carTrip.getBMS_RMC_ModuleTempMin());
        carTripOutput.setStartbmssoc(Convert.toDouble(carTrip.getBMS_SOC(), 0d));
        carTripOutput.setStartbmssoe(Convert.toDouble(carTrip.getBMS_SOE(), 0d));
        carTripOutput.setStartbmssoh(Convert.toDouble(carTrip.getBMS_SOH(), 0d));
        //carTripOutput.setTripstartdate(DateUtil.date(carTrip.getItem_time()).toString("YYYY-MM-dd"));
        carTripOutput.setModel_code(carTrip.getModel_code());
        carTripOutput.setBms_swversion(carTrip.getBms_swversion());

        return carTripOutput;
    }

    /**
     * 构造行程结束数据
     *
     * @param carTrip       当前流式数据
     * @param carTripOutput 行程记录数据
     * @return carTripOutput
     */
    public static CarTripOutput constructCarTripEndData (CarTrip carTrip, CarTripOutput carTripOutput){
        carTripOutput.setEndincartemp(Convert.toDouble(carTrip.getInCarTemp(), 0d));
        carTripOutput.setEndbmsmoduletempmax(carTrip.getBMS_RMC_ModuleTempMax());
        carTripOutput.setEndbmsmoduletempaverage(carTrip.getBMS_ModuleTempaverage());
        carTripOutput.setEndbmsmoduletempmin(carTrip.getBMS_RMC_ModuleTempMin());
        carTripOutput.setEndbmssoc(Convert.toDouble(carTrip.getBMS_SOC(), 0d));
        carTripOutput.setEndbmssoe(Convert.toDouble(carTrip.getBMS_SOE(), 0d));
        carTripOutput.setEndbmssoh(Convert.toDouble(carTrip.getBMS_SOH(), 0d));
/*        Map<String, String> code = SupplyUtil.supplyCode(carTrip.getLatitude(), carTrip.getLongitude());
        if (ObjectUtil.isNotEmpty(code)){
            carTripOutput.setEndarea(code.get("adCode"));
            carTripOutput.setEndpoi(code.get("poiType"));
        }
        if (ObjectUtil.isNotEmpty(carTripOutput.getStartarea()) && ObjectUtil.isNotEmpty(carTripOutput.getEndarea())) {
            String startCode = StrUtil.sub(carTripOutput.getStartarea(), 0, 4);
            String endCode = StrUtil.sub(carTripOutput.getEndarea(), 0, 4);
            if (StrUtil.sub(carTripOutput.getStartarea(), 0, 4).equals(StrUtil.sub(carTripOutput.getEndarea(), 0, 4))) {
                carTripOutput.setTravelrange(0);
            } else if (StrUtil.sub(carTripOutput.getStartarea(), 0, 2).equals(StrUtil.sub(carTripOutput.getEndarea(), 0, 2))) {
                carTripOutput.setTravelrange(1);
            }else {
                carTripOutput.setTravelrange(2);
            }
        }*/

        return carTripOutput;
    }

    /**
     * 两条数据间隔
     *
     * @param startTid 开始记录TID
     * @param endTid   截止记录TID
     * @return 持续时间(单位 : 秒)
     */
    public static Long countDuration ( long startTid, long endTid){
        long duration = DateUtil.between(DateTime.of(startTid), DateTime.of(endTid), DateUnit.SECOND);
        if (duration == 0) {
            duration = 1;
        }
        return duration;
    }


    /**
     * 两条数据间隔
     *
     * @param startDateTime 开始时间
     * @param endDateTime   结束时间
     * @return 持续时间(单位 : 秒)
     */
    public static Long countDuration (DateTime startDateTime, DateTime endDateTime){
        long duration = DateUtil.between(startDateTime, endDateTime, DateUnit.SECOND);
        if (duration == 0) {
            duration = 1;
        }
        return duration;
    }

}


